# -*- coding:utf-8 -*-
# @Time: 2020/8/25 15:32
# @Author: liupengfei
# @File: serializers.py
from django.conf import settings
from rest_framework import serializers
from utils.serializersfield import BooleanCharField, ImageUploadCharField, BooleanCheckCharField
from .models import Worker


class WorkerSerializer(serializers.ModelSerializer):
    '''后台管理创建'''
    face_path = serializers.SerializerMethodField()
    status_check = BooleanCheckCharField(source='status', read_only=True)
    status_text = BooleanCharField(source='status', read_only=True)
    face_arr = ImageUploadCharField(source='face', read_only=True)

    def get_face_path(self, obj):
        if obj.face:
            return obj.face.get_url()
        return ''

    class Meta:
        model = Worker
        fields = '__all__'
